<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    button {
      z-index: 1;
      position: absolute;
      left: 50%;
      transform: translate(-50%, 200px);
      margin: 0 auto;
      width: 300px;
      height: 50px;
    }

    button:hover {
      background-color: skyblue;
      color: white;
    }

    @keyframes myDia {
      0% {
        opacity: 0;
      }

      25% {
        opacity: 0.2;
      }

      50% {
        opacity: 0.4;
      }

      75% {
        opacity: 0.7;
      }

      100% {
        opacity: 1;
      }
    }

    .dialogA {
      animation: myDia 1s;
    }

    .dialog {
      z-index: 3;
      position: absolute;
      left: 50%;
      transform: translate(-50%, 300px);
      opacity: 0;
      width: 200px;
      height: 100px;
      line-height: 100px;
      text-align: center;
      border: 1px solid black;
      display: none;
      background-color: #fff;
      border-radius: 10px;
      border: none;
      background-color: skyblue;
    }

    /* .shadow {
      overflow: hidden;
      position: absolute;
      top: 0;
      transition: 5s all;
      z-index: 2;
      display: none;
      width: 100vw;
      height: 100vh;
      background-color: gray;
      opacity: 0.8;
    } */
    .shadowTOP {
      overflow: hidden;
      position: absolute;
      top: -50%;
      transition: 1s all;
      z-index: 2;
      display: block;
      width: 100vw;
      height: 50vh;
      background-color: gray;
      opacity: 0.8;
    }

    .shadowBUTTON {
      overflow: hidden;
      position:fixed;
      bottom: -50%;
      /* top: 100%; */
      transition: 1s all;
      z-index: 2;
      display: block;
      width: 100vw;
      height: 50vH;
      background-color: gray;
      opacity: 0.8;
    }
  </style>
</head>

<body>
  <button class="btn" onclick="btn(this)" data-type="cx">点我</button>
  <div class="dialog">弹框</div>
  <div class="shadowTOP" onclick="btn(this)"data-type="gb"></div>
  <div class="shadowBUTTON" onclick="btn(this)"data-type="gb"></div>
  <script>
    var dia = document.querySelector('.dialog');
    var shadowTOP = document.querySelector('.shadowTOP');
    var shadowBUTTON = document.querySelector('.shadowBUTTON');
    var a = 0;
    function btn(elm){
      console.log(elm.getAttribute("data-type"));
switch(elm.getAttribute("data-type")){
  case "cx":  dia.style.animation = `myDia 3s`;
      dia.style.display = "block";
      dia.classList.toggle("dialogA")
      shadowTOP.style.display = "block";
      shadowBUTTON.style.display = "block";
      shadowTOP.style.transform = `translateY(50vh)`;
      shadowBUTTON.style.transform = `translateY(-50vh)`;
      break;
      case "gb":   dia.style.display = "none";
        shadowTOP.style.display = "none";
        shadowBUTTON.style.display = "none";
        break;
}
    }
      // dia.style.animation = `myDia 3s`;
      // dia.style.display = "block";
      // dia.classList.toggle("dialogA")
      // shadowTOP.style.display = "block";
      // shadowBUTTON.style.display = "block";
      // shadowTOP.style.transform = `translateY(50vh)`;
      // shadowBUTTON.style.transform = `translateY(-50vh)`;
      // var timer = setTimeout(() => {
      //   dia.style.display = "none";
      //   shadowTOP.style.display = "none";
      //   shadowBUTTON.style.display = "none";
      //   a = a + 1;
      //   if (a == 1) {
      //     clearTimeout(timer);
      //     a = 0;
      //   }
      // }, 1000);

    // }
  </script>
</body>

</html>